home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16110 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  57 lines

  1. Path: ix.netcom.com!news
  2. From: swampwiz@ix.netcom.com(Jean P. Laborde )
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: file descriptors and fstreams...
  5. Date: 9 Apr 1996 02:42:06 GMT
  6. Organization: Netcom
  7. Message-ID: <4kcipu$fe9@dfw-ixnews4.ix.netcom.com>
  8. References: <4k780i$dd5@beyond.escape.com>
  9. NNTP-Posting-Host: nor-la5-12.ix.netcom.com
  10. X-NETCOM-Date: Mon Apr 08  9:42:06 PM CDT 1996
  11.  
  12. In <4k780i$dd5@beyond.escape.com> ward@escape.com (Christian Ward)
  13. writes: 
  14. >
  15. >
  16. >Hi I'm a very beginner c++ programmer, although I've been doing C for
  17. a
  18. >while. I know there's a C function called fdopen which takes a file
  19. >descriptor and creates a stream for it so you can use fprintf, fscanf,
  20. >and all that other good stuff. Is there a similar function (or
  21. whatever)
  22. >that takes a file descriptor and does something to let you use << and
  23. >>
  24. >with it?
  25. >
  26. >Like I said I'm very new to C++ and I'm sorry that I don't have the
  27. >correct terminology for all this stuff.
  28. >
  29. >Justin
  30.  
  31. nice name, Justin - it's my father's middle name.
  32.  
  33. Try this:
  34.  
  35.  
  36. #include <iostream.h>
  37. #include <fstream.h>
  38. #include <conio.h>
  39.  
  40. ifstream in("in_file.txt");
  41. ofstream out("out_file.txt");
  42.  
  43. int i;
  44. cout << "Enter an integer" << endl;
  45. cin >> i;
  46. cout << endl << "you just entered " << i << endl;
  47.  
  48. // much nicer than the stupid '%d' stuff & when you really start
  49. understandin c++, you'll find elegant ways to format as well!
  50.  
  51. Comments Suggested,
  52. The Swamp Wizard
  53.  
  54.  
  55.  
  56.  
  57.